package com.dyw.spzx.manager.controller;

import com.dyw.spzx.manager.service.CategoryBrandService;
import com.dyw.spzx.model.dto.system.CategoryBrandDto;
import com.dyw.spzx.model.entity.product.Brand;
import com.dyw.spzx.model.entity.product.CategoryBrand;
import com.dyw.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "分类品牌接口")
@RestController
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {

    @Autowired
    private CategoryBrandService categoryBrandService;

    @Operation(summary = "根据分类id查询品牌")
    @GetMapping("findBrandByCategoryId/{categoryId}")
    public Result<List<Brand>> findBrandByCategoryId(@PathVariable("categoryId") Long categoryId ){
       List<Brand> brandList = categoryBrandService.findBrandByCategoryId(categoryId);
       return Result.ok(brandList);
    }

    @Operation(summary = "分页查询品牌分类列表")
    @GetMapping("{page}/{limit}")
    public Result<PageInfo<CategoryBrand>> findByPage(@PathVariable("page") Integer page,
                                                      @PathVariable("limit") Integer limit,
                                                      CategoryBrandDto categoryBrandDto) {
        PageInfo<CategoryBrand> categoryBrandPageInfo = categoryBrandService.findByPage(page,limit,categoryBrandDto);

        return Result.ok(categoryBrandPageInfo);
    }

    @Operation(summary = "添加品牌分类")
    @PostMapping("/save")
    public Result save(@RequestBody CategoryBrand categoryBrand) {
        categoryBrandService.save(categoryBrand);
        return Result.ok(null) ;
    }

    @Operation(summary = "修改品牌分类")
    @PutMapping("/updateById")
    public Result updateById(@RequestBody CategoryBrand categoryBrand) {
        categoryBrandService.updateById(categoryBrand);
        return Result.ok(null);
    }

    @Operation(summary = "删除分类")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id) {
        categoryBrandService.deleteById(id);
        return Result.ok(null);
    }


}
